﻿using System;
using System.Collections.Generic;
using System.Text;

namespace IllustratedCsharp7_ch18Generic_
{
    class Animal
    {
        public int NumberofLegs = 4;
    }
    class Dog : Animal
    { }

   
    /*
        关键字in指定了类型参数的逆变
        逆变允许更高的程序的派生类型作为输入参数
     */
    delegate void  Action1<in T>(T a);
   
    class Chapter18_10_Contravariance
    {
        static void ActOnAnimal(Animal a) { Console.WriteLine(a.NumberofLegs); }
        static void Main()
        {
            Action<Animal> act1 = ActOnAnimal;
            Action<Dog> dog1 = act1;

            dog1(new Dog());
        }
    }
}
